#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int L, M;
    cin >> L >> M;
    vector<char> tree(L+1);
    fill(tree.begin(), tree.end(), '1');
    for (int i=1; i<=M; ++i)
    {
        int s, e;
        cin >> s >> e;
        for (int j=s; j<=e; ++j)
        {
            tree[j] = '0';
        }
    }
    int cnt = 0;
    for (int i=0; i<=L; ++i)
    {
        if (tree[i] == '1') ++cnt;
    }
    cout << cnt;
    return 0;
}
